/**
 * Created by enixjin on 1/10/18.
 */
import "rxjs/add/operator/mergeMap";
import {User} from "../../../../entity/User";
import {UserService} from "../../../../service/userService";
import {AbstractUserRESTAction} from "../AbstractUserRESTAction";

export class UserUpdateRESTAction extends AbstractUserRESTAction {
    constructor(private payload: User,
                private userService: UserService,
                private _localKey: string) {
        super(_localKey);
        // clone to avoid reference conflict
        // this.payload = Object.assign({}, user);
    }

    send() {
        let data = Object.assign({},this.payload);
        // have to delete "deleted" flag here
        delete data.deleted;
        return this.userService.update(data);
    }

    updateLocal(local, _payload): void {
        // local.set(this._localKey, local.get(this._localKey).map(u => u.id === _payload.id ? _payload : u));
    }
}
